package ar.com.mindset.geometrics_wi.colorScheme;

/**
 * @author http://www.mindset-designs.com
 */
public class Legend implements Writable {

    public static enum LegendType {
        CONTINUOUS_LIST_LEGEND, BAR_LEGEND, LIST_LEGEND
    }

    private int squareSize = -1;
    private LegendType legendType;

    public Legend(LegendType type) {
        this.legendType = type;
    }

    public void setSquareSize(int squareSize) {
        this.squareSize = squareSize;
    }


    public void write(StringBuffer xml) {
        xml.append("<legend>");

        switch (this.legendType) {
            case BAR_LEGEND:
                xml.append("<barLegend>");
                break;

            case LIST_LEGEND:
                xml.append("<listLegend");
                this.writeSquareSize(xml);
                xml.append(">");
                break;

            case CONTINUOUS_LIST_LEGEND:
                xml.append("<continuousListLegend");
                this.writeSquareSize(xml);
                xml.append(">");
                break;
        }

        xml.append("</legend>");
    }

    private void writeSquareSize(StringBuffer xml) {
        if (this.squareSize != -1) {
            xml.append(" squareSize='").append(this.squareSize).append("'/");
        }
    }
}
